package cn.tedu.spring.file;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * PropertySource注解：引入外部属性文件
 */
@PropertySource("classpath:database.properties")
@Component
public class DatabaseConnect {
    // 通过 ${变量名} 获取对应的值
    @Value("${jdbc.url}")
    private String dbUrl;
    @Value("${jdbc.user}")
    private String username;
    @Value("${jdbc.password}")
    private String password;

    @Override
    public String toString() {
        return "DatabaseConnect{" +
                "dbUrl='" + dbUrl + '\'' +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
